/*
 * Created by JFormDesigner on Mon May 30 10:40:45 CST 2022
 */

package jw3.c10.view;


import jw3.c10.controllner.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author Brainrain
 */
public class VIPlogin extends JFrame {
    public VIPlogin() {
        initComponents();
        this.add(label1);
        this.add(label2);
        this.add(label3);
        this.add(textField1);
        this.add(textField2);
        this.add(comboBox1);
        this.add(button1);
        this.add(button2);
        this.setSize(800,600);
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    private static final String URL="jdbc:mysql://localhost:3006/yuncarddb",
    User="root",Pwd="123456",
    DriverName="com.mysql.jdbc.Driver";

    static {

        try {
            Class.forName(DriverName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        String Account=textField1.getText();
        String pwd=textField2.getText();

        UserinfoController uf=new UserinfoController();
        if (!Account.equals("")&&!pwd.equals("")){

            if (uf.login(Account,pwd)) {

            }else {
                JOptionPane.showMessageDialog(null,"账号或密码错误！请重新输入");
                textField1.setText("");
                textField2.setText("");
            }
        }else {
            JOptionPane.showMessageDialog(null,"账号或密码不能为空！");
        }

        uf.login(Account,pwd);
        if (comboBox1.getSelectedItem().toString()=="普通VIP" && uf.login(Account,pwd)){
            JOptionPane.showMessageDialog(null,"恭喜您升级普通VIP");
        }else if (comboBox1.getSelectedItem().toString()=="白金VIP" && uf.login(Account,pwd)){

            JOptionPane.showMessageDialog(null,"恭喜您升级白金VIP");

        }else if (comboBox1.getSelectedItem().toString()=="钻石VIP" && uf.login(Account,pwd)){
            JOptionPane.showMessageDialog(null,"恭喜你升级成钻石VIP");

        }else if (comboBox1.getSelectedItem().toString()=="至尊VIP" && uf.login(Account,pwd)){
            JOptionPane.showMessageDialog(null,"感谢您成为至尊VIP");

        }

    }

    private void comboBox1ItemStateChanged(ItemEvent e) {
        // TODO add your code here
        if (comboBox1.getSelectedItem().toString()=="普通VIP"){
            label5.setText("100");

        }else if (comboBox1.getSelectedItem().toString()=="白金VIP"){
            label5.setText("200");

        }else if (comboBox1.getSelectedItem().toString()=="钻石VIP"){

            label5.setText("400");
        }else if (comboBox1.getSelectedItem().toString()=="至尊VIP"){

            label5.setText("800");
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        label2 = new JLabel();
        textField1 = new JTextField();
        label3 = new JLabel();
        comboBox1 = new JComboBox();
        button1 = new JButton();
        button2 = new JButton();
        label4 = new JLabel();
        label5 = new JLabel();
        textField2 = new JTextField();

        //======== this ========
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u8bf7\u8f93\u5165\u8d26\u53f7:");
        contentPane.add(label1);
        label1.setBounds(235, 30, 100, label1.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u5bc6\u7801:");
        contentPane.add(label2);
        label2.setBounds(252, 70, 67, label2.getPreferredSize().height);
        contentPane.add(textField1);
        textField1.setBounds(420, 23, 105, textField1.getPreferredSize().height);

        //---- label3 ----
        label3.setText("\u8bf7\u9009\u62e9VIP\u7b49\u7ea7:");
        contentPane.add(label3);
        label3.setBounds(218, 125, 135, label3.getPreferredSize().height);

        //---- comboBox1 ----
        comboBox1.addItemListener(e -> comboBox1ItemStateChanged(e));
        contentPane.add(comboBox1);
        comboBox1.setBounds(402, 120, 140, comboBox1.getPreferredSize().height);

        //---- button1 ----
        button1.setText("\u786e\u5b9a");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(145, 285), button1.getPreferredSize()));

        //---- button2 ----
        button2.setText("\u53d6\u6d88");
        contentPane.add(button2);
        button2.setBounds(new Rectangle(new Point(350, 285), button2.getPreferredSize()));

        //---- label4 ----
        label4.setText("\u5347\u7ea7\u5145\u503c:");
        contentPane.add(label4);
        label4.setBounds(240, 170, 90, 25);

        //---- label5 ----
        label5.setText("100");
        contentPane.add(label5);
        label5.setBounds(440, 170, 65, 30);
        contentPane.add(textField2);
        textField2.setBounds(420, 65, 105, 30);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
        comboBox1.addItem("普通VIP");
        comboBox1.addItem("白金VIP");
        comboBox1.addItem("钻石VIP");
        comboBox1.addItem("至尊VIP");
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JLabel label2;
    private JTextField textField1;
    private JLabel label3;
    private JComboBox comboBox1;
    private JButton button1;
    private JButton button2;
    private JLabel label4;
    private JLabel label5;
    private JTextField textField2;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
